<template>
  <div class="list">
    <div class="item" v-for="item in zeroDetails?.details || []" :key="item.id">
      <ZeroItem :ZeroData="item" />

      <div class="btn-list">
        <el-button type="primary" circle @click="removeFromCart(item.id)">-</el-button>
        <span>{{ item.quantity || 0 }}</span>
        <el-button type="primary" circle @click="addToCart(item.id)">+</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import ZeroItem from "./ZeroItem.vue";
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
  name: "ZeroList",
  data() {
    return {
      Zero: [],
    };
  },
  components: {
    ZeroItem,
  },
  computed: {
    ...mapState({
      coffees: state => state.coffees,
    }),
    zeroDetails() {
      return this.coffees.find(coffee => coffee.id === '3');
    }
  },
  mounted() {
    this.getlist();
  },
  methods: {
    getlist: function () {
      this.$axios
        .get("/coffees/coffees", {
          params: {
            id: 3,
          },
        })
        .then((response) => {
          this.Zero = response.data[0].details;
          console.log(this.Zero);
        });
    },
    ...mapMutations({
      addToCart: 'addToCart',
      removeFromCart: 'removeFromCart',
    }),
    ...mapActions(['fetchCoffees']),
  },
  created() {
    this.fetchCoffees();
  }
};
</script>

<style>
.list {
  display: flex;
  justify-content: space-around;
}

.img-wrap {
  width: 250px;
  height: auto;
}

.item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.btn-list {
  width: 150px;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
</style>
